package com.icehand.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 自定义实现servlet
 * Created by icehand on 2017/5/12.
 */
@WebServlet(urlPatterns = "/myServlet/*",description = "my servlet")
public class MyServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		System.out.println("This is a get request");
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		out.println("<html>");
		out.println("<head>");
		out.println("<title>My Servlet</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>这是get请求</h1>");
		out.println("</body>");
		out.println("</html>");
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		System.out.println("Do post");

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		out.println("<html>");
		out.println("<head>");
		out.println("<title>My Servlet</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>这是Post请求</h1>");
		out.println("</body>");
		out.println("</html>");

	}
}
